﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<eCRAM.WebSite.Models.CramModels>" %>

<%@ Import Namespace="eCRAM.Model" %>
<%@ Import Namespace="eCRAM.Tools" %>
<%@ Import Namespace="eCRAM.WebSite.Tools" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    eCram - Détail d'un cram
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript" src="../../Content/Scripts/cram.js"></script>
    <script type="text/javascript">
        $(document).ready(function () { onDocumentReady(); });

        $(document).ready(function () {
            $('#Attachments').click(function (e) {
                e.preventDefault();  //stop the browser from following 


                var name = $('#Attachments :selected').text();
                if (name != null)
                    $('#AttachmentName').val(name);
            });

        });

        $(document).ready(function () {
            $('#Download').click(function (e) {
                e.preventDefault();  //stop the browser from following 
                var name = $('#Attachments :selected').text();
                if (name != null && name.length > 0)
                    window.location.href = '/Attachments/' + name;
            });
        });



        $(document).ready(function () {
            $('#Print').click(function (e) {
                e.preventDefault();  //stop the browser from following 
                var regex = "^printcheck_";
                var printcols = $(':regex(id,' + regex + ')');
                printcols.show();
                $('#checkheader').show();
                $('#PrintCramAction').show();

                $('#trAddActivity').hide();
                $('#PrintAction').hide();

                $('#CancelAction').show();
                $('#SaveAction').hide();

                var regex = "^delete_";
                var deletecols = $(':regex(id,' + regex + ')');
                deletecols.hide();

                $('#delete_header').hide();

                var regex = "^addActivity_";
                var addActivitycols = $(':regex(id,' + regex + ')');
                addActivitycols.hide();


            });
        });

        

    </script>
    <h2>
        Détail d'un cram</h2>
    <div>
        <form id="CramTable" method="post" enctype="multipart/form-data">
        <%=Html.ValidationMessage("SubmitCram") %>
        <fieldset>
            <%=Html.HiddenFieldsForValueObject("model", Model)%>
            <%=Html.HiddenFieldsForValueObjectCollection("model.CramlinesModel", Model.CramlinesModel)%>
            <%=Html.Hidden("UserRole", Model.UserRole)%>
            <%=Html.Hidden("CramStatus", Model.Status)%>
            <%
                var listIdConges = string.Join(", ", ViewData.GetHolidaysActivityList().Select(x => x.Value));
                Response.Write(Html.Hidden("listIdHolidays", listIdConges));

                var listIdAstreinte = string.Join(", ", ViewData.GetAstreintesActivityList().Select(x => x.Value));
                Response.Write(Html.Hidden("listIdAstreinte", listIdAstreinte));
            %>
            <table>
                <tr>
                    <td>
                        <b>Utilisateur :</b>
                    </td>
                    <td>
                        <%=Html.DropDownListWithSubmitOnChange("CramDetails", model => model.UserId, ViewData.GetUsersList(), "CramTable", "", !SessionTools.UserIsAdministratorOrProjectLeader )%>
                    </td>
                    <td>
                        <b>Statut :</b>
                    </td>
                    <td id="StatutLabel">
                        <%=Html.Encode(Model.StatusLabel)%>
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Mois :</b>
                    </td>
                    <td>
                        <%=Html.DropDownListWithSubmitOnChange("CramDetails", model => model.Month, ViewData.GetMonthList(), "CramTable", "")%>
                    </td>
                    <td>
                        <b>Année :</b>
                    </td>
                    <td>
                        <%=Html.DropDownListWithSubmitOnChange("CramDetails", model => model.Year, ViewData.GetYearList(), "CramTable", "")%>
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>
                            <label for="comment">
                                Commentaire :</label></b>
                    </td>
                    <td>
                        <%=Html.TextAreaFor(model => model.Comment, new { style = "width: 350px; height:82px", maxlength = "255" })%>
                    </td>
                </tr>
            </table>
        </fieldset>
        <fieldset>
            <table >
                <tr border="0">
                    <td >
                        <table align="left" class="TableAction">
                            <tr>
                              <%--  <td id="td_validate" class="CellAction">
                                    <%=Html.HyperLink("ValidateCram", "visible", "ValidateCram", "Valider", "CramTable", "")%>
                                </td>--%>
                                <td id="td_submit" class="CellAction">
                                    <%= Html.Image("SubmitCram", "~/Content/Images/mail_send.png", "Soumettre", "CramTable", "", "ToolbarIcon")%>
                                </td>
                                <td id="CancelAction" class="CellAction">
                                    <%= Html.Image("CancelPrint", "~/Content/Images/cancel.png", "Annuler", "CramTable", "", "ToolbarIcon")%>
                                </td>
                                <td id="SaveAction" class="CellAction">
                                    <%= Html.Image("SaveCram", "~/Content/Images/save_all.png", "Enregistrer", "CramTable", "", "ToolbarIcon")%>
                                </td>
                                <td id="PrintAction" class="CellAction">
                                    <%= Html.Image("Print", "~/Content/Images/printer1.png", "Choix Impression", "", "", "ToolbarIcon")%>
                                </td>
                                <td id="PrintCramAction" class="CellAction">
                                    <%= Html.Image("PrintCram", "~/Content/Images/printer3.png", "Imprimer", "CramTable", "", "ToolbarIcon")%>
                                </td>
                                <td id="ExportToPdfAction" class="CellAction">
                                    <%= Html.Image("ExportToPDF", "~/Content/Images/PDF.png", "Exporter au format PDF", "CramTable", "", "ToolbarIcon")%>
                                </td>
                                <td id="ExportAstreintesToPdfAction" class="CellAction">
                                    <%= Html.Image("ExportAstreintesToPDF", "~/Content/Images/PDF_Astreinte.png", "Exporter au les astreintes au format PDF", "CramTable", "", "ToolbarIcon")%>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td border="0">
                        <%    
                    
                         
                            var cramDate = new DateTime(Model.Year != 0 ? Model.Year : DateTime.Now.Year, Model.Month != 0 ? Model.Month : DateTime.Today.Month, 1);
                            var workingDays = WorkingDay.MonthWorkingDays(cramDate.Year, cramDate.Month);

                            // Liste des jours
                            var strWorkingDays = string.Join(", ", workingDays.Select(x => (x ? "1" : "0")));
                            Response.Write(Html.Hidden("hidDays", strWorkingDays));
                        %>
                        <table id="tableCram" class="CramGrid">
                            <thead>
                                <th id="checkheader" class='cellDayHeader'>
                                    &nbsp;
                                </th>
                                <th id="delete_header">
                                    &nbsp;
                                </th>
                                <th class="CellCramTitleHeader">
                                    Projet / Mission
                                </th>
                                <%
                                    var i = 1;
                                    foreach (var dayLabel in ViewData.GetDaysByMonth(Model.Year, Model.Month))
                                    {
                                        Response.Write(string.Format("<th class='cellDayHeader'>{0} <br />{1}</th>", Html.Encode(dayLabel), Html.Encode(i++)));
                                    } 
                                %>
                                <th class='cellDayHeader'>
                                    Total
                                </th>
                            </thead>
                            <%
                                if (Model.CramlinesModel != null && Model.CramlinesModel.Count > 0)
                                {

                                    Response.Write(Html.Hidden("id", ""));
                                    foreach (var item in Model.CramlinesModel)
                                    {
                                        Response.Write(string.Format("<tr id='tr_{0}'>", item.Activity.Id)); %>
                                        <td id="<%=string.Format("printcheck_{0}",item.Id)%>" class="ReadonlyCellDay">
                                            <%=Html.CheckBox(string.Format("selection_{0}",item.Id),item.Selected)%>
                                            <%
                                                if (item.Selected)
                                                {
                                                    Response.Write(Html.Hidden(string.Format("selected_{0}", item.Id)));
                                                }
                            
                                            %>
                                        </td>
                                        <td id="<%=string.Format("addActivity_{0}",item.Id)%>">
                                            <%= Html.Hidden(string.Format("idCramLine_{0}", item.Activity.Id), item.Id)%>
                                            <%= Html.Hidden(string.Format("StatusCramLine_{0}", item.Activity.Id), item.Status)%>
                                            <%= Html.Image(string.Format("delete_{0}", item.Activity.Id), "~/Content/Images/delete.png","Supprimer", "CramTable", "return;")%>
                                        </td>
                                        <td>
                                            <%=Html.Encode(item.Activity.Name)%>
                                        </td>
                                        <%
                                        int k = 0;
                                        foreach (var rate in item.Rates)
                                        {
                                            var idTextbox = string.Format("day_{0}_{1}", k + 1, item.Activity.Id);
                                            var className = "Day";
                                            var cellClassName = "CellDay";
                                            if (!workingDays[k])
                                            {
                                                cellClassName = "CellHoliday";
                                                className = "Holiday";
                                            }

                                            if (item.Status != (int)CramStatus.New && !SessionTools.UserIsAdministratorOrProjectLeader)
                                            {
                                                cellClassName = "Readonly" + cellClassName;
                                                className = "Readonly" + className;
                                            }

                                            Response.Write(string.Format("<td class='{0}'>", cellClassName));
                                            Response.Write(Html.TextBox(idTextbox, rate.Value == 0 ? "" : rate.Value.ToString("0.#"),
                                                                        new
                                                                            {
                                                                                @readonly = "readonly",
                                                                                MaxLength = 3,
                                                                                @class = className
                                                                            }));
                                            Response.Write("</td>");

                                            k++;
                                        }
                        
                            %>
                            <td class="ReadonlyCellDay">
                                <%=Html.TextBox(string.Format("Total_{0}", item.Activity.Id), item.Total.ToString("0.#"), new { @readonly = "readonly", @class = "totalActivity" })%>
                            </td>
                            <% Response.Write("</tr>");
                        }
                    }%>
                            <tr id="trAddActivity">
                                <td class="CellActivityAction">
                                    <img id="imgAddActivity" src="/Content/Images/add.png" class="Icon" title="Ajouter une activité" alt="Ajouter une activité" />
                                    <img id="imgCancel" src="/Content/Images/delete.png" class="Icon" title="Annuler" alt="Annuler"/>
                                </td>
                                <td>
                                    <%=Html.DropDownList("cbActivity", ViewData.GetUserActivityList(Model.UserId))%>
                                    <img id="imgCheck" src="/Content/Images/ok.png" class="Icon" title="Valider" alt="Valider" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </fieldset>
        <fieldset>
            <table align="left" class="TableMetrics">
                <tr>
                    <td style="width:10px">
                        <b>Jours travaillés : </b>
                    </td>
                    <td class="ReadonlyCellDay">
                        <input id="txtTotalWorkedDays" type="text" readonly="readonly" class="totalActivity"
                            value="<%=Html.Encode(Model.WorkedDays.ToString("0.#"))%>" />
                    </td>
                </tr>
                <tr>
                    <td style="width:10px">
                        <b>Jours d'absence : </b>
                    </td>
                    <td class="ReadonlyCellDay">
                        <input id="txtTotalHolidays" type="text" readonly="readonly" class="totalActivity"
                            value="<%=Html.Encode(Model.VacationDays.ToString("0.#"))%>" />
                    </td>
                </tr>
                <tr>
                    <td style="width:10px">
                        <b>Jours ouvrés : </b>
                    </td>
                    <td class="ReadonlyCellDay">
                        <input id="txtTotalWorkingDays" type="text" readonly="readonly" class="totalActivity"
                            value="<%=Html.Encode(Model.WorkingDays.ToString("0.#"))%>" />
                    </td>
                </tr>
            </table>
            <table align="right" class="TableDownload">
                <tr>
                    <td colspan="2">
                        <input type="file" name="Attachment" id="Attachment" /> (10 Mo max.)
                    </td>
                </tr>
                <tr>
                    <td rowspan="3" style="width: 300px">
                        <%=Html.ListBox("Attachments",ViewData.GetCramAttachmentList(Model.Id),new { style="width : 300px" }) %>
                    </td>
                    <td>
                        <%=Html.Hidden("AttachmentName","") %>
                        <%= Html.Image("AddAttachment", "~/Content/Images/add.png", "Ajouter", "CramTable", "")%>
                    </td>
                </tr>
                <tr>
                    <td>
                        <%= Html.Image("DownloadAttachment", "~/Content/Images/2dowarrow.png", "Télécharger", "CramTable", "")%>
                    </td>
                </tr>
                <tr>
                    <td>
                        <%= Html.Image("DeleteAttachment", "~/Content/Images/delete.png", "Supprimer", "CramTable", "")%>
                    </td>
                </tr>
            </table>
        </fieldset>
        </form>
    </div>
</asp:Content>
